package com.lognsoft.btest;

public class StringOp 
{
	public static class KeyValue
	{
		String key;
		String value;
		
		public KeyValue (String a, String b)
		{
			key = a;
			value = b;
		}
		
		public KeyValue (String s, int ch, boolean not_null) 
		{
			if (s == null)
			{
				if (not_null)
				{
					key = value = "";
				}
				else
				{
					key = value = null;
				}
				return;
			}
			
			int ind = s.indexOf(ch);
			
			if (ind < 0)
			{
				if (not_null)
				{
					key = s;
					value = "";
				}
				else
				{
					key = value = null;
				}
			}
			else
			{	
				key = s.substring(0,ind).trim();
				value = s.substring(ind+1);
			}
		}
	};
	
	/* $() */
	public static boolean is_valid_id(String s)
	{
		for (int i = 0; i <s.length(); i++)
		{
			char ch = s.charAt(i);
			
			boolean ok = (ch >='0' && ch <='9') ||
						 (ch >='a' && ch <='z') ||
						 (ch >='A' && ch <='Z') ||
						 ch == '.' ||
						 ch == '+' ||
						 ch == '-' ||
						 ch == '_';
			
			if ( ok == false)
			{
				return false;
			}
		}
		
		return true;	
	}
	
	public static String getValueOfExpress(String s, int from)
	{
		return "";
	}
	
	public static String RemoveBracket(String s,String left,String right)	
	{
		int i = 0, len;
		
		if (s == null)
		{
			return s;
		}
		
		len = s.length();
		
		for (i = 0; i < len / 2 ; i++)
		{
			boolean ok = false;
			
			for (int kk = 0; kk < left.length(); kk++)
			{
				if ( s.charAt(i) == left.charAt(kk) &&
					 s.charAt(len - 1 - i) == right.charAt(kk) )
				{
					ok = true;
					break;
				}
			}
			
			if (ok == false)
			{
				break;
			}
		}
		
		if (i > 0 )
		{
			return s.substring(i, len - i);
		}
		else
		{
			return s;
		}
	}
}
